<template>
    <el-drawer v-model="drawer" :title="title" :size="size" :destroy-on-close="destroyOnClose" :close-delay=500 >
        <div class="formDrawer">
            
            <div class="body">
                <slot></slot>
            </div>
            <div class="actions">
                <el-button type="primary" @click="$emit('submit')" :loading="loading">{{ confirmText }}</el-button>
                <el-button type="default" @click="close">取消</el-button>
            </div>
        </div>
  </el-drawer>

</template>

<script setup>
import {ref} from 'vue'

 defineProps({
    title: String,
    size: {
        type: String,
        default: "40%"
    }, 
    destroyOnClose: {
        type: Boolean,
        default: false
    },
    confirmText: {
        type: String,
        default: "提交"
    }
})


const loading=ref(false)

const drawer = ref(false)

const showLoading=()=>loading.value=true

const closeLoading=()=>loading.value=false

const open=()=>drawer.value=true

const close=()=> drawer.value=false 

defineExpose({ open,close,showLoading,closeLoading })
</script>

<style>
    .formDrawer{
        width: 100%;
        height: 100%;
        position: relative;
        @apply flex flex-col;
    }

    .formDrawer .body{
        flex: 1;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 50px;
        overflow-y: auto;
    }

    .formDrawer .actions{
        height: 50px;
        @apply mt-auto flex items-center;
    }
</style>